package com.crack.nga2.span;

import android.graphics.Bitmap;
import android.support.v4.util.LruCache;

import com.android.volley.toolbox.ImageLoader;

/**
 * 图片缓存
 * Created by Administrator on 2016/1/11.
 */
public class BitmapCache extends LruCache<String, Bitmap> implements ImageLoader.ImageCache{
    public static int MAX_SIZE;
    private static BitmapCache bitmapCache;

    public static BitmapCache getInstance() {
        if (bitmapCache == null) {
            synchronized (BitmapCache.class) {
                bitmapCache = new BitmapCache(MAX_SIZE);
            }
        }
        return bitmapCache;
    }

    private BitmapCache(int maxSize) {
        super(maxSize);
    }

    @Override
    protected int sizeOf(String key, Bitmap value) {
        return value.getRowBytes() * value.getHeight() / 1024;
    }


    @Override
    public Bitmap getBitmap(String url) {
        return get(url);
    }

    @Override
    public void putBitmap(String url, Bitmap bitmap) {
        put(url,bitmap);
    }
}
